const CryptoJS = require("crypto-js")
// console.log(ctx.helper.encrypt('this','egg'))
// console.log(ctx.helper.decrypt('U2FsdGVkX1+w14hsxW0GC+Ovjm53LzZqSVcSMNDOFoA=','egg'))
module.exports = {
  // 加密
  encrypt(text, key) {
    return CryptoJS.AES.encrypt(text, key).toString();
  },
  // 解密
  decrypt(cipherText, key) {
    let bytes = CryptoJS.AES.decrypt(cipherText, key);
    return bytes.toString(CryptoJS.enc.Utf8);
  },
  // service处理msg
  processInformation(dataStaus, data, msg, code, httpState, path) {
    let res = {
      msg: msg,
      code: code,
      httpState: httpState,
      path: path
    }
    if (path) {
      dataStaus ? res.userId = data[0].userId : null
      dataStaus ? res.name = data[0].name : null
    }
    res.data = dataStaus ? data : []
    console.log('\x1B[31m%s\x1B[0m', res)
    return res
  }
}